package com.spring.aop.xml;

import java.util.Arrays;
import java.util.List;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class LoggingAspect {

	public void beforMethod(JoinPoint joinPoint){
		String methodName=joinPoint.getSignature().getName();
		List<Object> args=Arrays.asList(joinPoint.getArgs());
		
		System.out.println("前置通知：the method:"+methodName+" begin with "+args);
	}
	
	public void afterMethod(JoinPoint joinPoint){
		String methodName=joinPoint.getSignature().getName();
		System.out.println("后置通知：the method:"+methodName);
	}
	public void afterReturnning(JoinPoint joinpoint, Object result) {
        String methodName = joinpoint.getSignature().getName();
        System.out.println("返回通知：The method "+ methodName +" ends with " + result);
    }
	
	public void afterThrowing(JoinPoint joinPoint,Exception exception){
		String methodName=joinPoint.getSignature().getName();
		System.out.println("异常通知：the method"+methodName);
	}
	
	public Object aroundMethod(ProceedingJoinPoint point){
		Object result=null;
		String methodName=point.getSignature().getName();
		try {
			//ǰ��֪ͨ
			System.out.println("the method"+methodName+" begins with"+ Arrays.asList(point.getArgs()));
			result=point.proceed();
			System.out.println("the method"+methodName+" ends with"+result);
		} catch (Throwable e) {			
//			�쳣֪ͨ
			System.out.println("the method"+methodName+e);
			throw new RuntimeException();
		}
		System.out.println("the method:"+methodName+"ends");
		return result;
	}
	
	
	
}
